package com.haoe.service.impl;

import com.haoe.entity.OrderDish;
import com.haoe.mapper.OrderDishMapper;
import com.haoe.service.OrderDishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 80305082
 * @Date: 2021/3/16
 * @Description: 一个订单包含的菜品service实现层
 */
@Slf4j
@Service
public class OrderDishServiceImpl implements OrderDishService {

    @Autowired
    private OrderDishMapper orderDishMapper;

    @Override
    public List<OrderDish> selectByOrderId(Long orderId) {
        return orderDishMapper.selectByOrderId(orderId);
    }

    @Override
    public int deleteByOrderId(Long orderId) {
        return orderDishMapper.deleteByOrderId(orderId);
    }

    @Override
    public int insert(Long menuDishId, Long orderId, int count) {
        OrderDish orderDish = OrderDish.builder().menuDishId(menuDishId)
                .orderId(orderId).count(count).build();
        return orderDishMapper.saveOrderDish(orderDish);
    }
}
